<template>
	<view>
		<view>
			<u-navbar title=" " 
				back-icon-color="#000000" 
				:background="{ background: '#ffffff'}" :border-bottom="false">
			</u-navbar>
		</view>
		<view class="friendInfo">
			<view class="img">
				<u-image 	:src="applyFriendInfo.avatar"
							mode="aspectFill" width="120" height="120" border-radius="12">
					<u-loading slot="loading"></u-loading>
					<view slot="error"
							class="u-flex u-row-center u-col-center  u-p-t-10"
							style="width: 90rpx;height: 90rpx;background-color: #f1f1f1;border-radius: 12rpx;">
						<view>
							<image src="/static/image/default/default-user/default-user.png" 
									style="width: 64rpx;height: 64rpx;"></image>
						</view>
					</view>
				</u-image>
			</view>
			<view class="friendInfo-desc u-p-t-10">
				<view class="friendInfo-desc-name">
					<text class="u-m-r-10" style="font-size: 42rpx;">{{applyFriendInfo.realName}}</text>
				</view>
				<view class="friendInfo-desc-gray u-m-t-10">地区：{{parseAddress(applyFriendInfo.address)}}</view>
			</view>
		</view>
		
		<template v-if="fromWith=='from'">
			<view>
				<u-cell-group>
					<u-gap height="20" bg-color="#eee" margin-top="1" margin-bottom="1"></u-gap>
					<u-cell-item :arrow="false" :border-bottom="false">
						<view class="u-flex u-row-center u-col-center"
								style="font-size: 40rpx;color: #909399;text-align: center;">
							<view>
								<text style="margin-left: 10rpx;">等待对方验证</text>
							</view>
						</view>
					</u-cell-item>
				</u-cell-group>
			</view>
		</template>
		<template v-else>
			<u-cell-group>
				<u-gap height="20" bg-color="#eee" margin-top="1" margin-bottom="1"></u-gap>
				<u-cell-item title="设置备注"  :border-bottom="false" 
				:title-style="titleStyle"
				 @click="setFiendTag"></u-cell-item>
				 <u-gap height="20" bg-color="#eee" margin-top="1" margin-bottom="1"></u-gap>
				 <u-cell-item :arrow="false" :border-bottom="false" @click="aggreApply()">
				 	<view class="u-flex u-row-center u-col-center"
				 			style="font-size: 40rpx;color: #19BE6B;text-align: center;">
				 		<view>
				 			<text style="margin-left: 10rpx;">通过验证</text>
				 		</view>
				 	</view>
				 </u-cell-item>
			</u-cell-group>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				titleStyle: {
					marginLeft: '10rpx',
					color: '#000000',
					fontSize: "36rpx",
				},
				applyFriendInfo:null,
				fromWith:'',
			};
		},
		onLoad(option) {
			let that=this;
			that.applyFriendInfo=JSON.parse(decodeURIComponent(option.applyFriendInfo));
			console.log("applyFriendInfo",that.applyFriendInfo);
			let fromWith=that.applyFriendInfo.fromWith;
			if(fromWith.startsWith(this.vuex_userInfo.id)){
				console.log("等待验证");
				this.fromWith="from";
			}else{
				this.fromWith="to";
			}
		},
		methods:{
			//地址信息格式化
			parseAddress:function(address){
				let addressStr="中国";
				if(address!=null&&address.length>0){
					let addressObj= JSON.parse(address);
					let provice= addressObj.province.label;
					let city=addressObj.city.label;
					addressStr=provice+" "+city;
				}
				return addressStr;
			},
			//设置标签
			setFiendTag() {
				this.globalUtil.utilAlert("不能进,没完事~敬请期待");
				return;
			},
			aggreApply:function(){
				let that=this;
				let param={
					applyUserId:that.applyFriendInfo.id,
					status:1
				};
				that.$u.api.imUser.handleFriendApply(param).then(res => {
					if(res.code==200&&res.data!=null){
						console.log("通过审核",res.data);
						this.$u.route({
							url: "/pages/tabbar/contact/friends/friendHome",
							params:{
								  friendId:that.applyFriendInfo.id,
								  backAction:0 //表示要回到通讯录页面
							}
						})
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.slot-wrap {
		display: flex;
		align-items: center;
		/* 如果您想让slot内容占满整个导航栏的宽度 */
		flex: 1;
		width: 100%;
		/* 如果您想让slot内容与导航栏左右有空隙 */
		padding: 0 30rpx;
		flex-direction: row;
		justify-content: flex-end;
	}

	.perch {
		height: 10rpx;
	}

	.friendInfo {
		display: flex;
		justify-content: flex-start;
		align-items: flex-start;
		padding: 20rpx 30rpx 40rpx 40rpx;
		background-color: #FFFFFF;

		.img {
			display: block;
			width: 130rpx;
			height: 130rpx;
			border-radius: 10rpx;
		}

		&-desc {
			padding-left: 30rpx;

			&-name {
				font-weight: bold;
				font-size: 36rpx;
				transform: translateY(-10rpx);
				color: #000000;
			}

			&-gray {
				color: $u-tips-color;
				font-size: 30rpx;
			}
		}
	}
</style>
<style>
	page{
		background-color: #eeeeee;
	}
</style>
